package com.grape.demo20220803.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @Author pan_jin
 * @Description: $
 * @Date: 2022/8/9 9:49
 * @Version: 1.0.0
 * @Slogan: 梦想还是要有的万一实现了呢
 */
public class MasterDataSourceConfiguration {

    @Bean("masterDataSourceProperties")
    @ConfigurationProperties("spring.datasource-master")
    DataSourceProperties dataSourceProperties(){
        return new DataSourceProperties();
    }

    @Bean("masterDataSource")
    DataSource dataSource(@Autowired @Qualifier("masterDataSourceProperties") DataSourceProperties ds){
        return ds.initializeDataSourceBuilder().build();
    }
}
